<template>
  <div class="app-container">
    <el-card>
      <!--工具栏-->
      <div class="head-container">
         <eHeader :permission="permission"/>
        <!--<crudOperation :permission="permission" />-->
      </div>
      <!--工具栏-->

      <!--表单组件-->

      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="applicant" label="申请人"/>
        <el-table-column prop="phoneNum" label="联系手机"/>
        <el-table-column prop="email" label="邮箱"/>
        <el-table-column prop="jobName" label="职位名称"/>
        <el-table-column prop="city" label="工作地点"/>
        <el-table-column prop="quantity" label="薪资">
          <template slot-scope="scope">
            <el-button type="primary" size="mini">{{scope.row.salaryDown}}k</el-button>-
            <el-button type="primary" size="mini">{{scope.row.salaryUp}}k</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <el-button v-if="scope.row.status === 0" type="primary" size="mini">待查看</el-button>
            <el-button v-else-if="scope.row.status === 1"type="success" size="mini">通过初筛</el-button>
            <el-button v-else="scope.row.status === 2"type="warning" size="mini">拒绝</el-button>
          </template>
        </el-table-column>
        <el-table-column  label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <!--<udOperation
              :data="scope.row"
              :permission="permission"
            />-->
            <el-button @click="showResume(scope.row)" type="primary" size="mini">简历</el-button>
            <el-button @click="passEvent(scope.row)" v-if="scope.row.status === 0" type="success" size="mini">
              通过
            </el-button>
            <el-button @click="rejectEvent(scope.row)" v-if="scope.row.status === 0" type="danger" size="mini">
              拒绝
            </el-button>
          </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
      <pagination />
    </el-card>

    <el-dialog
      append-to-body
      :close-on-click-modal="false"
      :before-close="cancelResume"
      :visible="visibleResume"
      title="简历"
      width="800px"
    >

      <div v-if="form" style="border-bottom: 1px dashed #778899; margin-left: 10px;">
        <div style="margin-left: 60px; margin-bottom: 20px;font-weight: bold">
          基本信息
        </div>
      </div>
      <div style="margin-left: 80px; margin-top: 20px">
        <el-form ref="form" :model="form" size="small" label-width="80px">

          <div>
            <el-row :gutter="20">
              <el-col :span="6">
                <span>{{ applicant }}|{{ form.jobIntention }}</span>
              </el-col>
              <el-col :span="5">
                <span>{{ sexE(form.sex) }}|{{ form.age }}</span>
              </el-col>
              <el-col :span="6">
                <span>{{ form.english }}</span>
              </el-col>
              <el-col :span="5" :offset="2" class="time">
                <span>{{ form.address }}</span>
              </el-col>
            </el-row>
          </div>

        </el-form>
      </div>

      <div v-if="eduForm" style="border-bottom: 1px dashed #778899; margin-left: 10px; margin-top: 30px">
        <div style="margin-left: 60px; margin-bottom: 20px;font-weight: bold">教育经历</div>
      </div>
      <div style="margin-left: 80px; margin-top: 20px">
        <el-form ref="form" :model="eduForm" size="small" label-width="80px">
          <el-row :gutter="20">
            <el-col :span="4">
              <span>{{ eduForm.name }}</span>
            </el-col>
            <el-col :span="3">
              <span>{{ eduForm.professional }}</span>
            </el-col>
            <el-col :span="3">
              <span>{{ educationE(eduForm.education) }}</span>
            </el-col>
            <el-col :span="10" :offset="2" class="time">
              <span>{{ eduForm.startTime }}-{{ eduForm.endTime }}</span>
            </el-col>
          </el-row>
          <div style="margin-top: 20px">
            <span>    {{ eduForm.descriptions }}</span>
          </div>
        </el-form>
      </div>

      <div v-if="form" style="border-bottom: 1px dashed #778899; margin-left: 10px; margin-top: 30px; ">
        <div style="margin-left: 60px; margin-bottom: 20px;font-weight: bold">专业技能</div>
      </div>
      <div style="margin-left: 80px; margin-top: 20px; margin-bottom: 30px">
        <el-form ref="form" :model="form" size="small" label-width="80px">
          {{form.ability}}
        </el-form>
      </div>

      <div v-if="expForm" style="border-bottom: 1px dashed #778899; margin-left: 10px;">
        <div style="margin-left: 60px; margin-bottom: 20px;font-weight: bold">实习经历</div>
      </div>
      <div style="margin-left: 80px; margin-top: 20px">
        <el-form ref="form" :model="expForm" size="small" label-width="80px">
          <el-row :gutter="20">
            <el-col :span="4">
              <span>{{ expForm.name }}</span>
            </el-col>
            <el-col :span="3">
              <span>{{ expForm.job }}</span>
            </el-col>
            <el-col :span="10" :offset="2" class="time">
              <span>{{ expForm.startTime }}-{{ expForm.endTime }}</span>
            </el-col>
          </el-row>
          <div style="margin-top: 20px">
            <span>    {{ expForm.performance }}</span>
          </div>
        </el-form>
      </div>

      <div v-if="proForm" style="border-bottom: 1px dashed #778899; margin-left: 10px; margin-top: 30px">
        <div style="margin-left: 60px; margin-bottom: 20px;font-weight: bold">工作经历</div>
      </div>
      <div style="margin-left: 80px; margin-top: 20px">
        <el-form ref="form" :model="proForm" size="small" label-width="80px">
          <el-row :gutter="20">
            <el-col :span="4">
              <span>{{ proForm.name }}</span>
            </el-col>
            <el-col :span="10" :offset="2" class="time">
              <span>{{ proForm.startTime }}-{{ proForm.endTime }}</span>
            </el-col>
          </el-row>
          <div style="margin-top: 20px">
            <span>    {{ proForm.background }}</span>
          </div>
          <div style="margin-top: 20px">
            <span>    {{ proForm.performance }}</span>
          </div>
        </el-form>
      </div>

      <div v-if="form" style="border-bottom: 1px dashed #778899; margin-left: 10px; margin-top: 30px">
        <div style="margin-left: 60px; margin-bottom: 20px;font-weight: bold">个人评价</div>
      </div>
      <div style="margin-left: 80px; margin-top: 20px">
        <el-form ref="form" :model="form" size="small" label-width="80px">
          {{form.personalSummary}}
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="text" @click="cancelResume">
          关闭
        </el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import crudApplicant, { edit } from '@/api/ceamApplicant'
import { hrGetResume } from '@/api/ceamResume'
import eHeader from './header'
import CRUD, { presenter} from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import udOperation from '@crud/UD.operation'

// crud交由presenter持有
const crud = CRUD({
  title: '我的投递',
  url: 'api/application',
  sort: ['sort,asc', 'id,desc'],
  crudMethod: { ...crudApplicant }
})

export default {
  components: { eHeader, crudOperation, pagination, udOperation },
  mixins: [presenter(crud)],
  data() {
    return {
      delLoading: false,
      visibleResume: false,
      applicant: null,
      form: {},
      eduForm: {},
      expForm: {},
      proForm: {},
      studentList: [],
      permission: {
        add: ['admin', 'results:add'],
        edit: ['admin', 'results:edit'],
        del: ['admin', 'hrJob:del']
      }
    }
  },
  created() {
    this.$nextTick(() => {
      //this.init()
    })
  },
  methods: {
    checkPermission,
    cancelResume() {
      this.visibleResume = false;
    },
    sexE(sex) {
      if (sex === 0) {
        return "女";
      } else {
        return "男";
      }
    },
    educationE(education) {
      if (education === 0) {
        return "高中";
      } else if (education === 1) {
        return "专科";
      } else if (education === 2) {
        return "本科";
      } else if (education === 3) {
        return "硕士";
      }  else {
        return "博士";
      }
    },
    showResume(data) {
      console.log('applicant==', data.applicant)
      this.applicant = data.applicant;

      this.loadResume(data.applicantId);
      this.visibleResume = true;
    },
    loadResume(applicantId) {
      hrGetResume({applicantId: applicantId}).then(res =>{
        this.form.id = res.id;
        this.form = res;
        this.eduForm = res.edu;
        this.eduForm.id = res.edu.id;
        this.expForm = res.exp;
        this.expForm.id = res.exp.id;
        this.proForm = res.pro;
        this.proForm.id = res.pro.id;
      })
    },
    passEvent(data) {
      data.status = 1;
      edit(data).then(res => {
        this.$message({
          message: '成功',
          type: 'success'
        });

      }).catch(error => {
        this.$message({
          message: '失败',
          type: 'warning'
        });
      })
    },
    rejectEvent(data) {
      data.status = 2;
      edit(data).then(res => {
        this.$message({
          message: '成功',
          type: 'success'
        });

      }).catch(error => {
        this.$message({
          message: '失败',
          type: 'warning'
        });
      })
    }
  }
}
</script>

<style scoped>

</style>
